{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改机构编号</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="userAdd" id="userAdd" >
                        <input type="hidden" name="id" value="{$id}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">机构原编号：</label>
                            <div class="input-group col-sm-4">
                                <input id="code" type="text" class="form-control" name="code" value="{$oldCode}" disabled>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">新编号后三位：</label>
                            <div class="input-group col-sm-4">
                                <input id="new_code" type="text" class="form-control" name="new_code" placeholder="请输入3位新编号，例如：001">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript" src="__JS__/Crop.js"></script>
<script type="text/javascript">
    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            $(e).closest(".form-control").css("color","#737373");
        },
        success: function(e) {
            // e.closest(".form-group").removeClass("has-error").addClass("has-success")
            $(e).closest(".form-group").removeClass("has-error");
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            if(r.is("#groupid")){
                e.appendTo(r.parent());
            }
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    }), $().ready(function() {
        var e = "<i class='fa fa-times-circle'></i> ";
        jQuery.validator.addMethod("selectNoe", function(value, element) {
            var returnVal = true;
            var level = $("#groupid").val();
            if(level==""){
                returnVal = false;
            }
            return returnVal;
        }, e+"请选择机构");
        $("#userAdd").validate({
            rules: {
                new_code: {
                    required: !0,
                },
            },
            messages: {
                new_code: {
                    required: e + "请输入新编号",
                },
            },
            submitHandler: function(form) { //通过之后回调
//进行ajax传值
//                 var formData = new FormData($("#userAdd" )[0]);
                var level = $("#groupid").val();
                if(level==""){
                    $('.yanse').css("color","#ED5666");
                    $('#groupid_chosen').children().eq(0).css("border","1px solid #ED5666");
                    $("#myEditors").css("display","");
                    $("#myEditors").html("<i class='fa fa-times-circle'></i> 请选择机构");
                }else {
//                    $('button').attr('disabled', 'disabled');
                    $.ajax({
                        url: "{:url('editCode')}",
                        type: "post",
                        dataType: "json",
                        data: $("#userAdd").serialize(),
                        success: function (data) {
                            if (data.code == 200) {
                                wk.success(data.msg,1,"{:url('mechanism/index')}");
                            } else {
                                $('button').removeAttr('disabled');
                                wk.error(data.msg,2,'');
                                return false;
                            }
                        }
                    });
                }
            },
        })
    });
</script>
</body>
</html>